package com.example.jack.community.persenter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.jack.community.R;
import com.example.jack.community.data.HomeHostsportBean;
import com.example.jack.community.data.HomeItemBean1;
import com.example.jack.community.data.HomePopularBean;
import com.example.jack.community.data.HomeRcViewpagerBean;
import com.example.jack.community.model.IHomeFragment;

import java.util.ArrayList;

/**
 * Created by vveng on 2017/11/2 20: 13
 *
 * @mail: vvengStruggle@163.com
 * 首页实现类
 */

public class HomeFragmentpersenter {
    private Context mContext;
    private IHomeFragment mIHomeFragment;
    private ArrayList<ImageView> mviewpagerData = new ArrayList<>(); //viewpager数组
    private ArrayList<HomePopularBean> mPopularData = new ArrayList<>(); //热门数组
    private ArrayList<HomeHostsportBean> mHostsportData = new ArrayList<>(); //今日数组

    private  ArrayList<HomeRcViewpagerBean> list = new ArrayList<>(); //轮播图数组

    private ArrayList<HomeItemBean1> mHomeItemBean1s = new ArrayList<>();
    public HomeFragmentpersenter(IHomeFragment IHomeFragment, Context context) {
        mIHomeFragment = IHomeFragment;
        mContext = context;
    }

    //加载热门recyclerview的数据
    public void loadPpData(){
        int ppImage[] = new int[]{R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx, R.drawable.tx};
        for(int i =0 ; i<ppImage.length;i++){
            HomePopularBean bean = new HomePopularBean();
            bean.setPopularImage(ppImage[i]);
            mPopularData.add(bean);
        }
       mIHomeFragment.loadPopularData(mPopularData);
    }

    //加载今日recyclerview的数据
    public void loadHsData(){
        int hsImage[] = new int[]{R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4, R.drawable.b5, R.drawable.b6};
        for(int i =0 ; i<hsImage.length;i++){
           HomeHostsportBean bean =new HomeHostsportBean();
            bean.setHostsportImage(hsImage[i]);
            mHostsportData.add(bean);
        }
        mIHomeFragment.loadHostsportData(mHostsportData);
    }

    //加载动态recyclerview的数据
    public void loadItemData(){
         ArrayList<String> urls = new ArrayList<>();
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-05-18251898_1013302395468665_8734429858911748096_n.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-04-18299181_1306649979420798_1108869403736276992_n.jpg");
        urls.add("http://ww1.sinaimg.cn/large/61e74233ly1feuogwvg27j20p00zkqe7.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-02-926821_1453024764952889_775781470_n.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-28-18094719_120129648541065_8356500748640452608_n.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-27-17934080_117414798808566_8957027985114791936_n.jpg?imageslim");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-25-13651793_897557617014845_571817176_n.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-24-18013547_1532023163498554_215541963087151104_n.jpg");
        urls.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-24-18094714_158946097967074_5909424912493182976_n.jpg");

        for (int i = 0 ; i<=5 ;i++){
            HomeItemBean1 bean1 = new HomeItemBean1();
            bean1.setUserId(i);
            bean1.setAvatarImage(R.drawable.tx);
            bean1.setContext("                    男士关注我，从头到脚的帮你改变自己");
            bean1.setTime("一分钟前");
            bean1.setUsername("jack");
            bean1.setUrls(urls);
            bean1.setBrowse("111"+i);
            bean1.setComment("222"+i);
            bean1.setNice("333"+i);
            mHomeItemBean1s.add(bean1);
        }
        mIHomeFragment.loadItemData(mHomeItemBean1s);
    }
    //加载动态recyclerview的数据
    public ArrayList<HomeItemBean1> updateloadItemData2(){
        ArrayList<HomeItemBean1> datas = new ArrayList<>();
        ArrayList<String> urls2 = new ArrayList<>();
        urls2.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-04-18299181_1306649979420798_1108869403736276992_n.jpg");
        for (int i = 0 ; i<=5 ;i++){
            HomeItemBean1 bean1 = new HomeItemBean1();
            bean1.setUserId(i);
            bean1.setAvatarImage(R.drawable.tx);
            bean1.setContext("                    男士关注我，从头到脚的帮你改变自己");
            bean1.setTime("一分钟前");
            bean1.setUsername("jack");
            bean1.setUrls(urls2);
            datas.add(bean1);
        }
        return  datas;
    }
    //加载动态recyclerview的数据
    public ArrayList<HomeItemBean1> addItemData2(){
        ArrayList<HomeItemBean1> datas = new ArrayList<>();
        ArrayList<String> urls2 = new ArrayList<>();
        urls2.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-04-18299181_1306649979420798_1108869403736276992_n.jpg");
        urls2.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-02-926821_1453024764952889_775781470_n.jpg");
        urls2.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-28-18094719_120129648541065_8356500748640452608_n.jpg");
        urls2.add("http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-27-17934080_117414798808566_8957027985114791936_n.jpg?imageslim");
        for (int i = 0 ; i<=1 ;i++){
            HomeItemBean1 bean1 = new HomeItemBean1();
            bean1.setUserId(i);
            bean1.setAvatarImage(R.drawable.tx);
            bean1.setContext("                    男士关注我，从头到脚的帮你改变自己");
            bean1.setTime("三分钟前");
            bean1.setUsername("justin");
            bean1.setUrls(urls2);
            datas.add(bean1);
        }
     //  mIHomeFragment.loadItemData(mHomeItemBean1s);
        return datas;
    }
    //清空首页动态数据
    public void clearItemData(){
        mHomeItemBean1s.clear();
    }

    public void loadRcView(){
        String[]  stringId  = new String[]{
                "http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-05-18251898_1013302395468665_8734429858911748096_n.jpg",
                "http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-04-18299181_1306649979420798_1108869403736276992_n.jpg",
                "http://ww1.sinaimg.cn/large/61e74233ly1feuogwvg27j20p00zkqe7.jpg",
                "http://7xi8d6.com1.z0.glb.clouddn.com/2017-05-02-926821_1453024764952889_775781470_n.jpg",
                "http://7xi8d6.com1.z0.glb.clouddn.com/2017-04-28-18094719_120129648541065_8356500748640452608_n.jpg",
        };
        View pointView = null;
        LinearLayout.LayoutParams layoutParams =null;
        for (int i = 0; i < stringId.length; i++) {
            HomeRcViewpagerBean bean = new HomeRcViewpagerBean();
            bean.setId(i);
            bean.setImageUrl(stringId[i]);
            pointView = new View(mContext);
            pointView.setBackgroundResource(R.drawable.selector_bg_point);
            layoutParams = new LinearLayout.LayoutParams(10, 10);
            if (i != 0) {
                //设置间隔
                layoutParams.leftMargin = 30;
                //默认所有的小圆点的没选中
                pointView.setEnabled(false);
            }
            //这个方法是使每个小点添加到线性布局中，但绝对绝对不可以加到if（！=0）这里面是从1开始检测
            mIHomeFragment.loadPoint(pointView,layoutParams);
            list.add(bean);
        }
       mIHomeFragment.loadRcViewpager(list);
    }

}
